package cn.v2tila.rsosa.management.controller;

import cn.v2tila.rsosa.management.entity.MessageEntity;
import cn.v2tila.rsosa.management.entity.MsgTemplateEntity;
import cn.v2tila.rsosa.management.service.MsgService;
import cn.v2tila.rsosa.management.service.MsgTepService;
import cn.v2tila.rsosa.management.utils.PageDataResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author v2tila on 19:23 2019/4/19
 */
@Controller
@RequestMapping(value = "msg")
public class MsgController {
    @Autowired
    private MsgService msgService;
    @Autowired
    private MsgTepService msgTepService;

    @RequestMapping(value = "msgInfo")
    public String toMsgInfo() {
        return "msg/msgInfo";
    }

    @RequestMapping(value = "msgTep")
    public String toMsgTep() {
        return "msg/msgTep";
    }

    @GetMapping(value = "getMsg")
    @ResponseBody
    public PageDataResult getMsg(@RequestParam("page") Integer page,
                                  @RequestParam("limit") Integer limit,
                                  MessageEntity messageEntity){
        if(messageEntity.getUniqueId().equals("")){
            messageEntity.setUniqueId(null);
        }

        return msgService.getMsg(page, limit,messageEntity);
    }

    @GetMapping(value = "getMsgTep")
    @ResponseBody
    public PageDataResult getMsgTep(@RequestParam("page") Integer page,
                                 @RequestParam("limit") Integer limit,
                                 MsgTemplateEntity msgTemplateEntity){
        if(msgTemplateEntity.getUniqueId().equals("")){
            msgTemplateEntity.setUniqueId(null);
        }

        return msgTepService.getMsgTep(page, limit,msgTemplateEntity);
    }
}
